package model

import "time"

/*
 * 员工类的实现
 * 成员变量里对于会费的计算
 * 薪资策略的计算
 * 发放薪水方式
 * 发放薪水时间计算
 */

type Employee struct {
	empid 			int
	name 			string
	address 		string

	classification	PaymentClassification
	schedule		PaymentSchedule
	method			PaymentMethod
	affiliation		Affiliation
}

func NewEmployee(empid int, name, address string) *Employee {
	return &Employee{empid: empid, name: name, address: address}
}

func (e *Employee) SetEmpid(empid int) {
	e.empid = empid
}

func (e *Employee) SetName(name string) {
	e.name = name
}

func (e *Employee) SetAddress(address string) {
	e.address = address
}

func (e *Employee) SetSchedule(paymentSchedule PaymentSchedule) {
	e.schedule = paymentSchedule
}

func (e *Employee) SetClassification(paymentClassification PaymentClassification) {
	e.classification = paymentClassification
}

func (e *Employee) SetMethod(paymentMethod PaymentMethod) {
	e.method = paymentMethod
}

func (e *Employee) SetAffiliation(affiliation Affiliation) {
	e.affiliation = affiliation
}

func (e *Employee) GetEmpid() int {
	return e.empid
}

func (e *Employee) GetName() string {
	return e.name
}

func (e *Employee) GetAddress() string {
	return e.address
}

func (e *Employee) GetClassification() PaymentClassification {
	return e.classification
}

func (e *Employee) GetSchedule() PaymentSchedule {
	return e.schedule
}

func (e *Employee) GetMethod() PaymentMethod {
	return e.method
}

func (e *Employee) GetAffiliation() Affiliation {
	return e.affiliation
}

// 是否是支付日期

func (e *Employee) IsPayDate(date time.Time) bool {
	return e.schedule.IsPayData(date)
}

func (e *Employee) GetPayPeriodStartDate(payPeriodEndDate time.Time) time.Time {
	return e.schedule.GetPayPeriodStartDate(payPeriodEndDate)
}

func (e *Employee) Payday(pc PayCheck) {
	// 薪水计算交由支付策略类计算
	grossPay := e.classification.CalculatePay(pc)
	// 应扣除项交由会费类处理
	deductions := e.affiliation.CalculateDeductions(pc)
	netPay := grossPay - deductions
	pc.SetGrossPay(grossPay)
	pc.SetNetPay(netPay)
	pc.SetDeductions(deductions)
	// 薪资发放交由员工选择的发放形式处理
	e.method.Pay(pc)
}